package com.bear.generator;

import com.bear.model.MainTemplateConfig;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.IOException;

/**
 * @Author : bear
 * Description :
 * @Create : 2024/11/6 - 17:12
 */
public class MainGenerator {
//    public static void main(String[] args) throws TemplateException, IOException {
//        //1.静态文件生成
//
//        //获取当前项目根目录
//        String projectPath = System.getProperty("user.dir");
//        System.out.println(projectPath);
//        //输入路径
//        String inputPath = projectPath + File.separator + "bear-generator-demo-projects" + File.separator + "acm-template";
//        System.out.println(inputPath);
//        //输出路径
//        String outputPath = projectPath;
//        //复制
////        copyFilesByHutool(inputPath,outputPath);
//        StaticGenerator.copyFileByRecursive(new File(inputPath), new File(outputPath));
//
//        //2.动态文件生成
//
//        String dynamicInputPath = System.getProperty("user.dir") + File.separator + "bear-generator-basic" + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
//        String dynamicOutputPath = projectPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";//这里动态生成文件后会覆盖静态的文件
//        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
//        mainTemplateConfig.setAuthor("bear");
//        mainTemplateConfig.setLoop(false);
//        mainTemplateConfig.setOutputText("结果：");
//        DynamicGenerator.doGenerate(dynamicInputPath, dynamicOutputPath, mainTemplateConfig);
//    }
    public static void doGenerate(Object model) throws TemplateException, IOException {
        String projectPath = System.getProperty("user.dir");
        System.out.println(projectPath);
        // 整个项目的根路径
        File parentFile = new File(projectPath).getParentFile();
//        System.out.println(parentFile);
        // 输入路径
        String inputPath = new File(parentFile, "bear-generator-demo-projects/acm-template").getAbsolutePath();
        System.out.println(inputPath);
        String outputPath = projectPath;
        // 生成静态文件
        StaticGenerator.copyFileByRecursive(new File(inputPath), new File(outputPath));
        // 生成动态文件
        String inputDynamicFilePath = projectPath + File.separator + "src/main/resources/templates/MainTemplate.java.ftl";
        System.out.println(inputDynamicFilePath);
        String outputDynamicFilePath = outputPath + File.separator + "acm-template/src/com/yupi/acm/MainTemplate.java";
        DynamicGenerator.doGenerate(inputDynamicFilePath, outputDynamicFilePath, model);
    }
    public static void main(String[] args) throws TemplateException, IOException {
        MainTemplateConfig mainTemplateConfig = new MainTemplateConfig();
        mainTemplateConfig.setAuthor("bear");
        mainTemplateConfig.setLoop(false);
        mainTemplateConfig.setOutputText("求和结果：");
        doGenerate(mainTemplateConfig);
    }
}
